package com.kyxx.mycommonproject.dianpu;

import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.kyxx.mycommonproject.R;
import com.kyxx.mycommonproject.base.BaseActivity0;
import com.kyxx.mycommonproject.utils.SizeUtils;
import com.kyxx.mycommonproject.wodedingdan.TabFragmentAdapter;

import java.util.ArrayList;
import java.util.List;

public class ShopActivity extends BaseActivity0 {
    private TabLayout tl;
    private ViewPager vp;
    private String[] titles = new String[]{"店铺首页", "全部宝贝", "新品上架"/*, "微淘动态"*/};
    private ImageView iv_shop;
    private TextView tv_shop;
    private TextView tv_focus;
    private Button btn_focus;
    private TextView tv_class;
    private TextView tv_contact;
    private CollapsingToolbarLayout ctl;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_shop);
    }

    @Override
    protected void findViewById() {
        tl = (TabLayout) findViewById(R.id.tabs);
        vp = (ViewPager) findViewById(R.id.viewpager);
        iv_shop = (ImageView) findViewById(R.id.iv_shop);
        tv_shop = (TextView) findViewById(R.id.tv_shop);
        tv_focus = (TextView) findViewById(R.id.tv_focus);
        btn_focus = (Button) findViewById(R.id.btn_focus);
        tv_class = (TextView) findViewById(R.id.tv_class);
        tv_contact = (TextView) findViewById(R.id.tv_contact);
        ctl = (CollapsingToolbarLayout) findViewById(R.id.ctl);
    }

    @Override
    protected void setListener() {
        btn_focus.setOnClickListener(onClickListener);
        tv_class.setOnClickListener(onClickListener);
        tv_contact.setOnClickListener(onClickListener);
    }

    @Override
    protected void processLogic() {
        loadToolBar("xxx旗舰店");
        ctl.setTitle("xxx旗舰店");
        ctl.setExpandedTitleTextAppearance(R.style.ShopCollapsingToolbarLayoutTextAppearance);
        ctl.setExpandedTitleMarginStart(SizeUtils.dp2px(this, 70));
        List<Fragment> fragments = new ArrayList<Fragment>();
        for (int i = 0; i < 1; i++) {
            ShopMainFragment myShopMainFragment = new ShopMainFragment();
            myShopMainFragment.setKey(titles[i]);
            fragments.add(myShopMainFragment);
        }
        ShopAllGoodsFragment shopAllGoodsFragment = new ShopAllGoodsFragment();
        shopAllGoodsFragment.setKey(titles[1]);
        fragments.add(shopAllGoodsFragment);
        ShopAllGoodsFragment shopNewGoodsFragment = new ShopAllGoodsFragment();
        shopNewGoodsFragment.setKey(titles[2]);
        fragments.add(shopNewGoodsFragment);
      /*  for (int i = 3; i < 4; i++) {
            ShopMainFragment myShopMainFragment = new ShopMainFragment();
            myShopMainFragment.setKey(titles[i]);
            fragments.add(myShopMainFragment);
        }*/
        vp.setAdapter(new TabFragmentAdapter(fragments, titles, getSupportFragmentManager(), context));
        tl.setupWithViewPager(vp);
        tl.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vp.setCurrentItem(tab.getPosition(), false);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.btn_focus:
                    break;
                case R.id.tv_class:
                    break;
                case R.id.tv_contact:
                    break;
            }
        }
    };
}
